﻿
<template>
<div class="card-fill layout-padding">
<el-card shadow="hover" class="layout-padding-auto" >
  <WtmSearcher v-model="searchDataMaterial" @search="()=>{getTableDataMaterial();}">
      <el-row>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="MaterialCode_FormItem" prop="MaterialCode" :label="$t('message.autotrans._Model_Material_MaterialCode')">
            <el-input v-model="searchDataMaterial.MaterialCode" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="MaterialType_FormItem" prop="MaterialType" :label="$t('message.autotrans._Model_Material_MaterialType')">
            <el-input v-model="searchDataMaterial.MaterialType" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="MaterialName_FormItem" prop="MaterialName" :label="$t('message.autotrans._Model_Material_MaterialName')">
            <el-input v-model="searchDataMaterial.MaterialName" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="MaterialVersion_FormItem" prop="MaterialVersion" :label="$t('message.autotrans._Model_Material_MaterialVersion')">
            <el-input v-model="searchDataMaterial.MaterialVersion" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="MeasureUnitCode_FormItem" prop="MeasureUnitCode" :label="$t('message.autotrans._Model_Material_MeasureUnitCode')">
            <el-input v-model="searchDataMaterial.MeasureUnitCode" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="Regular_FormItem" prop="Regular" :label="$t('message.autotrans._Model_Material_Regular')">
            <el-input v-model="searchDataMaterial.Regular" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="ShipRegular_FormItem" prop="ShipRegular" :label="$t('message.autotrans._Model_Material_ShipRegular')">
            <el-input v-model="searchDataMaterial.ShipRegular" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="MachineStatus_FormItem" prop="MachineStatus" :label="$t('message.autotrans._Model_Material_MachineStatus')">
            <el-select v-model="searchDataMaterial.MachineStatus" clearable>
               <el-option key="CREATED" value="CREATED" :label="$t('message.autotrans._Enum_BaseStatus_CREATED')"></el-option>
               <el-option key="USED" value="USED" :label="$t('message.autotrans._Enum_BaseStatus_USED')"></el-option>
               <el-option key="FORBIDDEN" value="FORBIDDEN" :label="$t('message.autotrans._Enum_BaseStatus_FORBIDDEN')"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="CreateTime_FormItem" prop="CreateTime" :label="$t('message.autotrans._Model_Material_CreateTime')">
            <el-date-picker v-model="searchDataMaterial.CreateTime" type='daterange' clearable></el-date-picker>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="UpdateTime_FormItem" prop="UpdateTime" :label="$t('message.autotrans._Model_Material_UpdateTime')">
            <el-date-picker v-model="searchDataMaterial.UpdateTime" type='daterange' clearable></el-date-picker>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="CreateBy_FormItem" prop="CreateBy" :label="$t('message.autotrans._Model_Material_CreateBy')">
            <el-input v-model="searchDataMaterial.CreateBy" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="UpdateBy_FormItem" prop="UpdateBy" :label="$t('message.autotrans._Model_Material_UpdateBy')">
            <el-input v-model="searchDataMaterial.UpdateBy" clearable></el-input>
        </el-form-item>

        </el-col>
      </el-row>

  </WtmSearcher>

  <div style="text-align: right;">
      <WtmButton v-auth="'/api/BaseInformation/Material/Create'" icon='fa fa-plus' type='primary' :button-text="$t('message.autotrans.SysCreate')" @click="OnCreateClick()"/>
    <WtmButton v-auth="'/api/BaseInformation/Material/BatchDelete'"  icon='fa fa-trash' type='danger' :button-text="$t('message.autotrans.SysDelete')" :confirm="$t('message._system.common.vm.deletetip')" @click="onBatchDelete()"/>
    <WtmButton v-auth="'/api/BaseInformation/Material/BatchEdit'" icon='fa fa-pencil-square' type='primary' :button-text="$t('message.autotrans.SysBatchEdit')" @click="OnBatchEditClick()"/>
    <WtmButton v-auth="'/api/BaseInformation/Material/Import'" icon='fa fa-tasks' type='primary' :button-text="$t('message.autotrans.SysImport')" @click="OnImportClick()"/>
    <WtmButton v-auth="'/api/BaseInformation/Material/MaterialExportExcel'"  icon='fa fa-arrow-circle-down' type='primary' :button-text="$t('message.autotrans.SysExport')" @click="onExport()"/>

  </div>
  <WtmTable ref="tableRefMaterial" v-bind="tableDataMaterial">
    <template #operation>
      <el-table-column :label="$t('message._system.common.vm.operate')" width="180">
        <template v-slot="scope">
            <WtmButton v-auth="'/api/BaseInformation/Material/Edit'" :is-text="true" icon='fa fa-pencil-square' type='warning' :button-text="$t('message.autotrans.SysEdit')" @click="OnEditrowClick(scope.row)"/>
          <WtmButton v-auth="'/api/BaseInformation/Material/{id}'" :is-text="true" icon='fa fa-info-circle' type='info' :button-text="$t('message.autotrans.Page详情')" @click="OnDetailsrowClick(scope.row)"/>
          <WtmButton v-auth="'/api/BaseInformation/Material/BatchDelete'"  icon='fa fa-trash' type='danger' :button-text="$t('message.autotrans.SysDelete')" :confirm="$t('message._system.common.vm.deletetip')" :is-text="true"  @click="onDelete(scope.row)"/>

        </template>
      </el-table-column>
    </template>
  </WtmTable>

</el-card>
</div>
</template>


<script setup lang="ts" name="message.autotrans._PageBaseInformationMaterialIndex;true;TyMES.BaseInformation.Controllers;Material">
import {  ElMessageBox, ElMessage,ElLoading } from 'element-plus';
import { defineAsyncComponent,reactive, ref, getCurrentInstance, onMounted, nextTick } from 'vue';
import { materialApi } from '/@/api/baseinformation/material';
import other from '/@/utils/other';
import fileApi from '/@/api/file';
import { useRouter } from "vue-router";
const ci = getCurrentInstance() as any;

const CreateDialog = defineAsyncComponent(() => import('./create.vue'));
const EditDialog = defineAsyncComponent(() => import('./edit.vue'));
const DetailsDialog = defineAsyncComponent(() => import('./details.vue'));
const BatchEditDialog = defineAsyncComponent(() => import('./batchedit.vue'));
const ImportDialog = defineAsyncComponent(() => import('./import.vue'));

const stateMaterial = reactive({
    
});

const searchDataMaterial = ref({
        MaterialCode: '',
        MaterialType: '',
        MaterialName: '',
        MaterialVersion: '',
        MeasureUnitCode: '',
        Regular: '',
        ShipRegular: '',
        MachineStatus: undefined,
        CreateTime: undefined,
        UpdateTime: undefined,
        CreateBy: '',
        UpdateBy: '',
});

// 定义变量内容
const tableRefMaterial = ref();
const tableDataMaterial = ref({
    // 列表数据（必传）
    data: [],
	// 表头内容（必传，注意格式）
	header: [
      {title:ci.proxy.$t('message.autotrans.Page物料编码'),key: 'Material_MaterialCode',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page物料类型'),key: 'Material_MaterialType',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page物料名称'),key: 'Material_MaterialName',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page物料版本'),key: 'Material_MaterialVersion',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page计量单位'),key: 'Material_MeasureUnitCode',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page正则校验'),key: 'Material_Regular',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page出货条码正则校验'),key: 'Material_ShipRegular',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page物料状态'),key: 'Material_MachineStatus',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans._AdminCreateTime'),key: 'Material_CreateTime',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans._AdminUpdateTime'),key: 'Material_UpdateTime',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans._AdminCreateBy'),key: 'Material_CreateBy',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans._AdminUpdateBy'),key: 'Material_UpdateBy',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans._AdminIsValid'),key: 'Material_IsValid',type: 'switch',isCheck: true},

	],
	// 配置项（必传）
	config: {
        total: 0, // 列表总数
		loading: true, // loading 加载
		isSerialNo: true, // 是否显示表格序号
		isSelection: true, // 是否显示表格多选
		isOperate: true, // 是否显示表格操作栏
	}
});
// 初始化表格数据
const getTableDataMaterial = () => {
    tableRefMaterial.value.doSearch(materialApi().search, searchDataMaterial.value)
        .catch((error: any) => {
			other.setFormError(ci, error);
		});
};
const OnCreateClick = () => {
    other.openDialog(ci.proxy.$t('message.autotrans.SysCreate'), CreateDialog, null, getTableDataMaterial)
};

const OnEditrowClick = (row: any) => {
    other.openDialog(ci.proxy.$t('message.autotrans.SysEdit'), EditDialog, row, getTableDataMaterial)
};

const OnDetailsrowClick = (row: any) => {
    other.openDialog(ci.proxy.$t('message.autotrans.Page详情'), DetailsDialog, row, getTableDataMaterial)
};

// 删除
const onDelete = (row: any) => {
    materialApi().delete([row.ID]).then(() => { getTableDataMaterial()})
};

const onBatchDelete = () => {
    const selectedrows = tableRefMaterial.value.getSelectedRows();
    const selectedids = selectedrows.map((x: any) => x.ID);
    if (selectedids.length > 0)
      materialApi().delete(selectedids).then(() => { getTableDataMaterial()})
    else
      ElMessage.error(ci.proxy.$t('message._system.common.vm.check'));
};

const OnBatchEditClick = () => {
    const selectedrows = tableRefMaterial.value.getSelectedRows();
    const selectedids = selectedrows.map((x: any) => x.ID);
    if (selectedids.length > 0)
      other.openDialog(ci.proxy.$t('message.autotrans.SysBatchEdit'), BatchEditDialog, selectedids, getTableDataMaterial)
    else
      ElMessage.error(ci.proxy.$t('message._system.common.vm.check'));
};

const OnImportClick = () => {
    other.openDialog(ci.proxy.$t('message.autotrans.SysImport'), ImportDialog, null, getTableDataMaterial)
};

const onExport = () => {
	const selected = tableRefMaterial.value.getSelectedRows();
	if (selected.length > 0) {
		materialApi().exportById(selected.map((x: any) => x.ID));
	}
	else {
		materialApi().export({});
	}
};

// 页面加载时
onMounted(() => {
    
        getTableDataMaterial();

});

// 暴露变量
defineExpose({

});
</script>

<style scoped lang="scss">

</style>

